﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using EHTWebsite.Code;
/// <summary>
/// Author: toanvt
/// CreatedDate: 12/12/2011
/// Description: Insert, Update Liên Hệ
/// </summary>
public partial class Administrator_AdminContactIU : System.Web.UI.Page
{
    public Int32 LienHeID = HangSo.DEFAULT_ID;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            LienHeID = Int32.Parse(Request.QueryString["LienHeID"].ToString());
        }
        catch (Exception)
        {
            LienHeID = HangSo.DEFAULT_ID;
        }

        if (LienHeID == -1)
        {
            Response.Redirect("AdminContacts.aspx");
        }
        else
        {
            EHTWebsite.Code.LienHe theLienHe = LienHeProvider.GetLienHeByLienHeID(LienHeID);

            if (theLienHe == null)
                Response.Redirect("AdminContacts.aspx");
            else
            {
                if (!Page.IsPostBack)
                    LoadContact();
            }
        }
    }

    /// <summary>
    /// Author: toanvt
    /// CreatedDate: 12/12/2011
    /// Description: lấy tin liên hệ
    /// </summary>
    private void LoadContact()
    {
        EHTWebsite.Code.LienHe theLienHe = LienHeProvider.GetLienHeByLienHeID(LienHeID);

        lbHoTen.Text = theLienHe.HoTen.ToString();
        lbNoiDung.Text = theLienHe.NoiDung.ToString();
        lbDiaChi.Text = theLienHe.DiaChi.ToString();
        lbDienThoai.Text = theLienHe.DienThoai.ToString();
        lbEmail.Text = theLienHe.Email.ToString();
        lbNgayLienHe.Text = theLienHe.NgayLienHe.Date.ToString();
        // Check trạng thái của liên hệ
        try
        {
            if (theLienHe.TrangThaiDoc)
                lbTrangThaiDoc.Text = "Đã xem";
            else
                lbTrangThaiDoc.Text = "Chưa xem";
        }
        catch (Exception)
        {
            lbTrangThaiDoc.Text = "Chưa xem";
        }
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect("AdminContacts.aspx");
    }

    protected void btnDelete_Click(object sender, EventArgs e)
    {
        LienHeProvider.DeleteLienHeByLienHeID(LienHeID);
        Response.Redirect("AdminContacts.aspx");
    }
}
